<?php
//Set up the system
require('config.include.php');
//Auth stuff
require('auth.include.php');
//Save data if given
$saved=false;
if(isset($_POST['settings'])) {
	$tmpFile=fopen('../ipblacklist.php','w+');
	$presettingsdata=explode("\n",fetch::unescapePostVar($_POST['settings']));
	$settingsdata=array_unique(str_replace(array("\n","\r"),array('',''),$presettingsdata));
	foreach($settingsdata as $index=>$aword)
		if($aword=='')
			unset($settingsdata[$index]);
	fwrite($tmpFile,DIE_MSG.serialize($settingsdata));
	fclose($tmpFile);
	$saved=true;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit IP Blacklist</title>
<link rel="stylesheet" href="admin.css" />
</head>

<body>
<div id="wrapper">
	<div id="header">
    	<?php echo('<a href="../" class="breadcrumb">'.SITE_TITLE.'</a> &raquo; <a href="dashboard.php" class="breadcrumb">Dashboard</a> &raquo; <a href="editblacklist.php" class="breadcrumb">Edit IP Blacklist</a>'); ?>
    </div>
    <div id="sidebar">
<?php
	require('nav.include.php');
?>
    </div>
    <div id="content">
        <div class="contentblock">
		<h2>Edit IP Blacklist</h2>
		<form action="editipblacklist.php" method="post">
			One partial or full IP per line, empty lines and duplicate entries are ignored.
			<textarea name="settings" cols="60" rows="30"><?php
				$list=substr(file_get_contents('../ipblacklist.php'),strlen(DIE_MSG));
				$listentries=unserialize($list);
				if(count($listentries)>0) {
					foreach($listentries as $word)
						echo($word."\n");
				}
			?></textarea>
			<br />
			<input type="submit" value="Save"/>
		</form>
		<?php
		if($saved)
			echo(count($settingsdata).' IP addresses saved.');
		?>
		</div>
    </div>
    <div id="footer">
    </div>
</div>
</body>
</html>